var _objectWithoutProperties2 = require("../../../@babel/runtime/helpers/objectWithoutProperties"), _excluded = [ "url" ], app = getApp();

Page({
    data: {
        keyword: "",
        list: [],
        logo_url: "",
        last_page: "",
        finished: !1,
        loading: !1,
        current_page: 1,
        keyWorkds: [],
        plugin: "message-base",
        apiOption: {},
        pluginOption: {},
        itemOption: {
            article_name: "article_name",
            creater_name: "creater_name",
            base_name: "base_name",
            created_at: "created_at"
        }
    },
    onLoad: function(t) {
        this.data.keyword = t.keyword || "", this.init(), this.getData();
    },
    init: function init() {
        var _this = this;
        this.data.list = [], this.data.current_page = 1, this.data.finished = !1, this.data.loading = !1, 
        this.data.pluginOption = {
            "message-base": {
                index: "plugin.message-base.frontend.article.index",
                params: function() {
                    return {
                        keyword: _this.data.keyword,
                        page: _this.data.current_page
                    };
                },
                callback: function callback(res) {
                    var _res$data = res.data, data = _res$data.data, logo = _res$data.logo, current_page = _res$data.current_page, last_page = _res$data.last_page, list = "" == _this.data.keyword ? data : data.filter(function(r) {
                        var str = eval("/".concat(_this.data.keyword, "/g")), newstr = '<span style="color:#e44848;">'.concat(_this.data.keyword, "</span>");
                        return r.article_name = r.article_name.replace(str, newstr), r;
                    });
                    _this.data.list = _this.data.list.concat(list), current_page >= last_page && (_this.data.finished = !0), 
                    _this.setData({
                        current_page: _this.data.current_page + 1,
                        list: _this.data.list,
                        logo_url: logo,
                        keyWorkds: res.data.keyword || _this.data.keyWorkds
                    });
                }
            },
            "project-template": {
                index: "plugin.project-template.frontend.knowledge.searchKnowledgeBaseList",
                params: function() {
                    return {
                        title: _this.data.keyword,
                        page: _this.data.current_page
                    };
                },
                callback: function callback(res) {
                    _this.current_page += 1;
                    var _res$data2 = res.data, data = _res$data2.data, current_page = _res$data2.current_page, last_page = _res$data2.last_page, list = "" == _this.data.keyword ? data : data.filter(function(r) {
                        var str = eval("/".concat(_this.data.keyword, "/g")), newstr = '<span style="color:#e44848;">'.concat(_this.data.keyword, "</span>");
                        return r.article_name = r.article_name && r.article_name.replace(str, newstr) || "", 
                        r;
                    });
                    _this.data.list = _this.data.list.concat(list), current_page >= last_page && (_this.data.finished = !0), 
                    _this.setData({
                        list: _this.data.list,
                        keyWorkds: res.data.keyword || _this.data.keyWorkds,
                        itemOption: {
                            article_name: "title",
                            base_name: "has_one_yz_supply_knowledge_base.title",
                            created_at: "release_time_at"
                        }
                    });
                }
            },
            "project-template-good": {
                flag: "project-template",
                index: "plugin.project-template.frontend.knowledge.searchKnowledgeBaseArticleList",
                params: function() {
                    return {
                        title: _this.data.keyword,
                        page: _this.data.current_page,
                        goods_id: _this.options.gid
                    };
                },
                callback: function callback(res) {
                    _this.data.current_page += 1;
                    var _res$data3 = res.data, data = _res$data3.data, current_page = _res$data3.current_page, last_page = _res$data3.last_page, list = "" == _this.data.keyword ? data : data.filter(function(r) {
                        var str = eval("/".concat(_this.keyword, "/g")), newstr = '<span style="color:#e44848;">'.concat(_this.data.keyword, "</span>");
                        return r.article_name = r.article_name && r.article_name.replace(str, newstr) || "", 
                        r;
                    });
                    _this.data.list = _this.data.list.concat(list), current_page >= last_page && (_this.data.finished = !0), 
                    _this.setData({
                        list: _this.data.list,
                        keyWorkds: res.data.keyword || _this.data.keyWorkds,
                        itemOption: {
                            article_name: "title",
                            base_name: "has_one_yz_supply_knowledge_base.title",
                            created_at: "release_time_at"
                        }
                    });
                }
            }
        };
        var _this$data = this.data, keyword = _this$data.keyword, current_page = _this$data.current_page;
        this.options.plu && (this.data.plugin = this.options.plu), this.data.apiOption = this.data.pluginOption[this.data.plugin], 
        this.setData({
            getPlugin: this.data.apiOption.flag ? this.data.apiOption.flag : this.data.plugin
        });
    },
    onChange: function(t) {
        this.setData({
            keyword: t.detail
        });
    },
    search: function() {
        this.init(), this.getData();
    },
    clickKeyword: function(t) {
        var a = t.target.dataset.key || t.currentTarget.dataset.key;
        this.setData({
            keyword: a
        }), this.search();
    },
    getData: function() {
        var t = this;
        if (!this.data.finished && !this.data.loading) {
            this.data.loading = !0;
            var a = app.getNetAddresss(this.data.apiOption.index);
            app._getNetWork({
                url: a,
                data: this.data.apiOption.params(),
                success: function(a) {
                    t.data.loading = !1, 1 === a.data.result ? t.data.apiOption.callback(a.data) : wx.showToast({
                        title: a.data.msg,
                        icon: "none"
                    });
                }
            });
        }
    },
    wxRouterLink: function(t) {
        var a = "", e = t.url, i = _objectWithoutProperties2(t, _excluded);
        Object.keys(i).forEach(function(t) {
            "" !== i[t] && (a += t + "=" + i[t] + "&");
        }), "" !== e && wx.navigateTo({
            url: e + "?" + a.slice(0, -1)
        });
    },
    onListClick: function(t) {
        var a = t.detail, e = a.id, i = a.base_id, s = a.knowledge_base_id;
        this.wxRouterLink({
            url: "/packageI/knowledge/knowledgeDetail/knowledgeDetail",
            id: e,
            bid: i || s,
            plu: this.data.getPlugin
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getData();
    },
    onShareAppMessage: function() {}
});